<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html">
<ui:composition template="/WEB-INF/views/oneColumnBody.xhtml">
    <f:loadBundle var="msg" basename="pl.pawluk.inz.web.SpringResourceBundle"/>
    <ui:define name="editDialogForm"> <ui:include src="editUser.xhtml"/></ui:define>
    <ui:define name="center_content">
        <h:form id="listForm" prependId="true">
            <div class="title_welcome"><h:outputText value="#{msg.userList}"/></div>
            <div class="features">
                <div class="title"></div>
                <p:toolbar id="editToolbar">
                    <p:toolbarGroup align="left">
                        <p:commandButton value="New" icon="ui-icon-document" actionListener="#{usersBean.createNew}"
                                         update=":editForm:editPanel" oncomplete="eDialog.show()"/>
                        <p:separator/>
                        <p:commandButton title="Delete" icon="ui-icon-trash"
                                         disabled="#{usersBean.user.email == null}"
                                         actionListener="#{usersBean.delete}"
                                         update=":listForm:editTable :gf:growl"/>
                        <p:commandButton type="button" title="Edit" icon="ui-icon-pencil"
                                         disabled="#{usersBean.user.email == null}"
                                         onclick="eDialog.show();"/>
                        <p:separator/>
                        <p:commandButton title="Refresh" icon="ui-icon-refresh" update=":listForm:editTable"/>
                        <p:separator/>
                        <p:commandButton ajax="false" title="Edit" icon="ui-icon-comment"
                                         disabled="#{usersBean.user.email == null}" action="coursesList"/>
                    </p:toolbarGroup>
                </p:toolbar>
                <p:dataTable id="editTable" var="user" value="#{usersBean.users}" scrollable="true"
                             scrollHeight="150"
                             selection="#{usersBean.user}" selectionMode="single" rowKey="#{user.id}">
                    <p:ajax event="rowSelect" update=":editForm:editPanel :listForm:editToolbar"/>
                    <p:ajax event="rowUnselect" listener="#{usersBean.onRowUnselect}"
                            update=":editForm:editPanel :listForm:editToolbar"/>
                    <p:column headerText="#{msg.name}">
                        <h:outputText value="#{user.firstName}"/>
                    </p:column>

                    <p:column headerText="#{msg.middleName}">
                        <h:outputText value="#{user.middleName}"/>
                    </p:column>

                    <p:column headerText="#{msg.surname}">
                        <h:outputText value="#{user.surname}"/>
                    </p:column>
                </p:dataTable>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
</html>